package com.example.administrator.myapplication;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;


public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private Button buttonWenzi1;
    private Button buttonWenzi2;
    private Button buttonWenzi3;
    private Button buttonWenzi4;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        buttonWenzi1 = (Button) findViewById(R.id.wenzi1);
        buttonWenzi1.setOnClickListener(this);
        buttonWenzi2 = (Button) findViewById(R.id.wenzi2);
        buttonWenzi2.setOnClickListener(this);
        buttonWenzi3 =  (Button) findViewById(R.id.wenzi3);
        buttonWenzi3.setOnClickListener(this);
        buttonWenzi4 = (Button) findViewById(R.id.wenzi4);
        buttonWenzi4.setOnClickListener(this);


    }
    public  void setSelected(){
        buttonWenzi1.setSelected(false);
        buttonWenzi2.setSelected(false);
        buttonWenzi3.setSelected(false);
        buttonWenzi4.setSelected(false);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.wenzi1 :
                setSelected();
                FragmentManager manager = getSupportFragmentManager();
                FragmentTransaction sd = manager.beginTransaction();
                sd.replace(R.id.ly_content,new OneFragment());
                buttonWenzi1.setSelected(true);
                sd.commit();
                break;

            case R.id.wenzi2 :
                setSelected();
                buttonWenzi2.setSelected(true);
                FragmentManager manager2 = getSupportFragmentManager();
                FragmentTransaction sd2 = manager2.beginTransaction();
                sd2.replace(R.id.ly_content,new TwoFragment());
                sd2.commit();
                break;

            case R.id.wenzi3 :
                setSelected();
                buttonWenzi3.setSelected(true);
                FragmentManager manager3 = getSupportFragmentManager();
                FragmentTransaction sd3 = manager3.beginTransaction();
                sd3.replace(R.id.ly_content,new SanFragment());
                sd3.commit();
                break;

            case R.id.wenzi4 :
                setSelected();
                buttonWenzi4.setSelected(true);
                FragmentManager manager4 = getSupportFragmentManager();
                FragmentTransaction sd4 = manager4.beginTransaction();
                sd4.replace(R.id.ly_content,new SiFragment());
                sd4.commit();
                break;
        }
    }
}
